home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / atarivdi.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  11.2 KB  |  429 lines

  1. /*
  2.  * $Id: atarivdi.trm,v 1.1 1995/06/14 12:22:17 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - atari.trm */
  7. /*
  8.  * Copyright (C) 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted,
  12.  * provided that the above copyright notice appear in all copies and
  13.  * that both that copyright notice and this permission notice appear
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed
  18.  * as patches to released version.
  19.  *
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  *
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Atari Screens working with the normal VDI
  26.  *     (this should include TT and big screens)
  27.  *
  28.  * AUTHORS
  29.  *  Alexander Lehmann
  30.  *  HE Koechling
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  *
  34.  * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
  35.  *
  36.  */
  37.  
  38. #ifndef GOT_DRIVER_H
  39. #include "driver.h"
  40. #endif
  41.  
  42. #ifdef TERM_REGISTER
  43. register_term(vdi)
  44. #endif           
  45.  
  46. #ifdef TERM_PROTO
  47.  
  48. /* function-prototypes */
  49. TERM_PUBLIC void VDI_options(void);
  50. TERM_PUBLIC void VDI_init(void);
  51. TERM_PUBLIC void VDI_reset(void);
  52. TERM_PUBLIC void VDI_graphics(void);
  53. TERM_PUBLIC void VDI_text(void);
  54. TERM_PUBLIC void VDI_move(unsigned int x, unsigned int y);
  55. TERM_PUBLIC void VDI_vector(unsigned int x, unsigned int y);
  56. TERM_PUBLIC void VDI_linetype(int lt);
  57. TERM_PUBLIC int VDI_text_angle(int ta);
  58. TERM_PUBLIC void VDI_put_text(unsigned int x, unsigned int y, char *str);
  59. TERM_PUBLIC int VDI_justify_text(enum JUSTIFY mode);
  60. TERM_PUBLIC void VDI_point(unsigned int x, unsigned int y, int number);
  61.  
  62. /* default to hi-res */
  63. #define VDI_XMAX 640
  64. #define VDI_YMAX 400
  65. #define VDI_VCHAR 16
  66. #define VDI_HCHAR 8
  67. #define VDI_HTIC (VDI_XMAX/100)
  68. #define VDI_VTIC VDI_HTIC
  69.  
  70. #define GOT_VDI_PROTO
  71. #endif /* TERM_PROTO */
  72.  
  73. #ifndef TERM_PROTO_ONLY
  74. #ifdef TERM_BODY
  75.  
  76. #ifdef __PUREC__
  77. /* why did they have to change these names ??? */
  78. #include <aes.h>
  79. #include <vdi.h>
  80. #include <tos.h>
  81. #else /* !__PUREC__ i.e. __GNUC__, maybe others */
  82. #include <aesbind.h>
  83. #include <vdibind.h>
  84. #include <osbind.h>
  85. #endif
  86.  
  87. #define VDI_yc(y) (VDI_maxycoord-(y))
  88. #define VDI_LINETYPES_MAX    11
  89. static int VDI_linetypes[VDI_LINETYPES_MAX] = {
  90.         0xffff, 0x1111,
  91.         0xffff, 0x5555, 0x3333, 0x7777,
  92.         0x3f3f, 0x0f0f, 0x5f5f, 0xe4e4, 0x55f5};
  93. static int VDI_lt;
  94. static int vdi_vdi_handle=-1;
  95. static int VDI_maxycoord;
  96. static int VDI_rotation;
  97. static int VDI_numcolors;
  98. static int pxy[128];            /* Maximum of 64 pixels per v_pline */
  99. static int pxy_index;
  100. static int VDI_colors[16];
  101. static int VDI_savecolors[16][3];
  102. static int VDI_numpalette;
  103. #define VDI_c_height_default 6 /* well, well ...               */
  104. static int VDI_c_height = VDI_c_height_default;
  105.  
  106. static void vdi_flush_line(void);
  107.  
  108. TERM_PUBLIC void VDI_options( )
  109. {
  110. #define VDIHEXERROR "palette values 3 hex digits, please"
  111. #define VDIHEIGHTERROR "expecting a character height"
  112.     char opt[4];
  113.     int i;
  114.     char *tok_end;
  115.  
  116.     term_options[0]='\0';
  117.     VDI_c_height=VDI_c_height_default;
  118.  
  119.     for( i=0 ; i<17 ; i++ ) {
  120.         if(END_OF_COMMAND) break;
  121.         if (token[c_token].length>3) {
  122.             VDI_numpalette=0;
  123.             VDI_c_height=VDI_c_height_default;
  124.             term_options[0]='\0';
  125.             int_error(VDIHEXERROR, c_token);
  126.         }
  127.  
  128.         capture( opt, c_token, c_token, 6 );
  129.         if (!i) {
  130.             VDI_c_height = strtoul( opt, &tok_end, 10 );
  131.             if( *tok_end!='\0' ) {
  132.                 VDI_numpalette=0;
  133.                 VDI_c_height=VDI_c_height_default;
  134.                 term_options[0]='\0';
  135.                 int_error(VDIHEIGHTERROR, c_token);
  136.             }
  137.             if( VDI_c_height>999 )
  138.                 VDI_c_height=999;  /* avoid opt length overflow */
  139.             sprintf( opt, "%d ", VDI_c_height );
  140.         }
  141.         else {
  142.             VDI_colors[i-1]=strtoul( opt, &tok_end, 16 );
  143.             if( *tok_end!='\0' ) {
  144.                 VDI_numpalette=0;
  145.                 VDI_c_height=VDI_c_height_default;
  146.                 term_options[0]='\0';
  147.                 int_error(VDIHEXERROR, c_token);
  148.             }
  149.  
  150.             sprintf( opt, "%03X ", VDI_colors[i-1] );
  151.         }
  152.         strcat( term_options, opt );
  153.         c_token++;
  154.     }
  155.     VDI_numpalette=(i==0 ? 0 : i-1);
  156. }
  157.  
  158. TERM_PUBLIC void VDI_init( )
  159. {
  160.     int work_in[11];
  161.     int work_out[57];
  162.     int i;
  163.     int hchar, wchar, dummy;
  164.     int rgb[3];
  165.     int num_save;
  166.     char *colors,*tok_end;
  167.  
  168.     if( VDI_numpalette==0 && (colors=getenv("GNUCOLORS")) && *colors ) {
  169.         for( i=0 ; i<17 ; i++ ) {
  170.             if (!i) {
  171.                 VDI_c_height = strtoul( colors, &tok_end, 10 );
  172.                  if( colors==tok_end ) {
  173.                     i=0;
  174.                     VDI_c_height=VDI_c_height_default;
  175.                     break;
  176.                 }
  177.            }
  178.             else {
  179.                 if( *colors=='\0' ) break;
  180.                 VDI_colors[i]=strtoul( colors, &tok_end, 16 );
  181.                 if( colors==tok_end || (unsigned)VDI_colors[i]>0xfff ) {
  182.                     i=0;
  183.                     break;
  184.                 }
  185.             }
  186.             colors=tok_end;
  187.  
  188.             while( *colors==' ' ) colors++;
  189.         }
  190.         VDI_numpalette=(i==0 ? 0 : i-1);
  191.     }
  192.  
  193.     vdi_vdi_handle=graf_handle( &wchar, &hchar, &dummy, &dummy );
  194.     if( !vdi_vdi_handle )
  195.         int_error("Fatal error opening virtual workstation", NO_CARET);
  196.  
  197.     for( i=0 ; i<10 ; work_in[i++]=1 );
  198.         work_in[10]=2;                  /* use raster coordinates */
  199.     v_opnvwk( work_in, &vdi_vdi_handle, work_out );
  200.     if( !vdi_vdi_handle )
  201.         int_error("Fatal error opening virtual workstation", NO_CARET);
  202.  
  203.     vst_height(vdi_vdi_handle, VDI_c_height, &dummy, &dummy, &wchar, &hchar);
  204.  
  205.     vs_clip( vdi_vdi_handle, 0, work_in ); /* turn clipping off */
  206.  
  207.     term->xmax=work_out[0]+1;
  208.     term->ymax=work_out[1]+1;
  209.     term->h_char=wchar;
  210.     term->v_char=hchar;    /* hchar stands for height this time */
  211.     term->h_tic=(work_out[0]+1)/100;
  212.     term->v_tic=term->h_tic;
  213.  
  214.     VDI_maxycoord=work_out[1];
  215.     VDI_numcolors=work_out[13];
  216.     pxy_index=0;
  217.  
  218.     for( i=0 ; i<VDI_numpalette ; i++ ) {
  219.         vq_color( vdi_vdi_handle, i, 1, VDI_savecolors[i] );
  220.  
  221.         rgb[0]=1000*(VDI_colors[i]>>8);
  222.         rgb[0]/=15;
  223.         rgb[1]=1000*((VDI_colors[i]>>4)&15);
  224.         rgb[1]/=15;
  225.         rgb[2]=1000*(VDI_colors[i]&15);
  226.         rgb[2]/=15;
  227.         vs_color(vdi_vdi_handle, i, rgb );
  228.     }
  229. #ifdef __PUREC__
  230. /* currently the PureC version runs as .prg and the GCC version runs as .ttp.
  231.    Let's hope that we soon figure out which way is the best */
  232.     v_hide_c(vdi_vdi_handle);
  233. #endif
  234. }
  235.  
  236. TERM_PUBLIC void VDI_reset( )
  237. {
  238.     int i;
  239.  
  240.     if( vdi_vdi_handle!=-1 ) {
  241.         for( i=0 ; i<VDI_numpalette ; i++ ) {
  242.             vs_color(vdi_vdi_handle, i, VDI_savecolors[i] );
  243.         }
  244. #ifdef __PUREC__
  245. /* see above */
  246.     v_show_c(vdi_vdi_handle, 0);
  247. #endif
  248.         v_clsvwk( vdi_vdi_handle );
  249.         vdi_vdi_handle=-1;
  250.     }
  251. }
  252.  
  253. TERM_PUBLIC void VDI_graphics( )
  254. {
  255.     int pxy[8];
  256.     MFDB mfdb;
  257.  
  258.     fflush( stdout );
  259.     fflush( stderr );
  260.     Cconws( "\033f" ); /* turn cursor off */
  261. /*  apparently v_clrwk doesn't work with overscan. We'll blit the screen clear.
  262.     v_clrwk( vdi_vdi_handle );
  263. */
  264.     mfdb.fd_addr=NULL; /* NULL means actual screen. So we don't need size etc. */
  265.  
  266.     pxy[0]=pxy[4]=0;
  267.     pxy[1]=pxy[5]=0;
  268.     pxy[2]=pxy[6]=term->xmax-1;
  269.     pxy[3]=pxy[7]=term->ymax-1;
  270.  
  271.     vro_cpyfm( vdi_vdi_handle, ALL_WHITE /*0*/, pxy, &mfdb, &mfdb );
  272.  
  273.     pxy_index=0;
  274. }
  275.  
  276. TERM_PUBLIC void VDI_text( )
  277. {
  278.     vdi_flush_line( );
  279.     Cnecin();        /* wait for any char --> enable screen dump */
  280.     Cconws( "\033e" );  /* turn cursor on again */
  281. }
  282.  
  283. TERM_PUBLIC void VDI_move( unsigned int x, unsigned int y )
  284. {
  285.     vdi_flush_line( );
  286.  
  287.     pxy_index=1;
  288.     pxy[0]=x;
  289.     pxy[1]=VDI_yc(y);
  290. }
  291.  
  292. TERM_PUBLIC void VDI_vector( unsigned int x, unsigned int y )
  293. {
  294.     pxy[2*pxy_index]=x;
  295.     pxy[2*pxy_index+1]=VDI_yc(y);
  296.     pxy_index++;
  297.  
  298.     if( pxy_index==64 ) {   /* we're all full */
  299.         vdi_flush_line( );
  300.     }
  301. }
  302.  
  303. TERM_PUBLIC void VDI_linetype( int lt )
  304. {
  305.     vdi_flush_line( );
  306.  
  307.     VDI_lt=lt;
  308. }
  309.  
  310. TERM_PUBLIC void VDI_put_text( unsigned int x, unsigned int y, char *str )
  311. {
  312.     int vchar=term->v_char;
  313.     int dummy;
  314.  
  315.     if( !strlen(str) ) return;
  316.  
  317.     if( x<0 ) x=0;
  318.     if( y<0 ) y=0;
  319.  
  320.     /* align text left and to middle of char height */
  321.     vst_alignment( vdi_vdi_handle, 0, 5, &dummy, &dummy );
  322.     vst_rotation( vdi_vdi_handle, (VDI_rotation ? 900 : 0) );
  323.     if( VDI_rotation ) 
  324.         v_gtext( vdi_vdi_handle, x-vchar/2+1, VDI_yc(y)-1, str );
  325.     else
  326.         v_gtext( vdi_vdi_handle, x+1, VDI_yc(y)-vchar/2+1, str );
  327. }
  328.  
  329. TERM_PUBLIC int VDI_text_angle( int ang )
  330. {
  331.     VDI_rotation=ang;
  332.  
  333.     return TRUE;
  334. }
  335.  
  336. TERM_PUBLIC int VDI_justify_text( enum JUSTIFY mode )
  337. {
  338.     return FALSE;
  339. }
  340.  
  341. TERM_PUBLIC void VDI_point(unsigned int x, unsigned int y, int number )
  342. {
  343.     int old_linetype;
  344.  
  345.     if( VDI_numcolors==2 ) {
  346.         line_and_point( x, y, number ); /* monochrome */
  347.     } else {
  348.     /* we map colors that exceed our limit to dotted lines, but we can't do
  349.        that with the markers (sortof a generalized line_and_point) */
  350.     old_linetype=VDI_lt;
  351.     if( VDI_lt>VDI_numcolors-2 )
  352.         VDI_linetype(VDI_lt%(VDI_numcolors-2)); /* same color, but no dots */
  353.         do_point( x, y, number );
  354.     VDI_linetype(old_linetype);
  355.     }
  356. }
  357.  
  358. static void vdi_flush_line( )
  359. {
  360.     int line_type;
  361.     int color_index;
  362.     int i;
  363.  
  364.     if( pxy_index>=2 ) {
  365.         if( VDI_numcolors==2 ) { /* Monochrome */
  366.             color_index=1;
  367.             line_type=VDI_lt;
  368.             if (line_type >= 0)
  369.                 line_type %= (VDI_LINETYPES_MAX - 2);
  370.         } else { /* Color */
  371.             if (VDI_lt<0) {
  372.                 color_index=1;
  373.                 line_type= VDI_lt;
  374.             }
  375.             else {
  376.                 color_index=2+VDI_lt%(VDI_numcolors-2);
  377.                 line_type=(VDI_lt/(VDI_numcolors-2)) % (VDI_LINETYPES_MAX - 2);
  378.             }
  379.         }
  380.  
  381.         vswr_mode( vdi_vdi_handle, MD_TRANS);
  382.         vsl_color( vdi_vdi_handle, color_index );
  383.  
  384.         vsl_type( vdi_vdi_handle, 7 );
  385.         vsl_udsty( vdi_vdi_handle, VDI_linetypes[line_type + 2] );
  386.  
  387.         v_pline( vdi_vdi_handle, pxy_index, pxy );
  388.     }
  389.  
  390.     if( pxy_index>=1 ) {
  391.         pxy[0]=pxy[2*(pxy_index-1)];
  392.         pxy[1]=pxy[2*(pxy_index-1)+1];
  393.         pxy_index=1;
  394.     }
  395. }
  396.  
  397. #endif /* TERM_BODY */
  398.  
  399. #ifdef TERM_TABLE
  400.  
  401. TERM_TABLE_START(vdi_driver)    
  402.     "vdi", "Atari VDI-Terminal",
  403.     VDI_XMAX, VDI_YMAX, VDI_VCHAR, VDI_HCHAR, 
  404.     VDI_VTIC, VDI_HTIC, VDI_options, VDI_init, VDI_reset, 
  405.     VDI_text, null_scale, VDI_graphics, VDI_move, VDI_vector, 
  406.     VDI_linetype, VDI_put_text, VDI_text_angle, 
  407.     VDI_justify_text, VDI_point, do_arrow, set_font_null,
  408.     0, TERM_CAN_MULTIPLOT, 0, 0
  409. TERM_TABLE_END(vdi_driver)
  410.  
  411. #undef LAST_TERM
  412. #define LAST_TERM vdi_driver
  413.  
  414. #endif /* TERM_TABLE */
  415.  
  416. #endif /* TERM_PROTO_ONLY */
  417.  
  418. #ifdef TERM_HELP
  419. START_HELP(vdi)
  420. "1 atari ST (via VDI)",
  421. "?set terminal vdi",
  422. "?vdi",
  423. " This terminal is the same as the `atari` terminal, except for the fact that",
  424. " it sends output to the screen via the VDI and not into AES-Windows.",
  425. "",
  426. " The `vdi` terminal has the same options as the `atari` terminal."
  427. END_HELP(vdi)
  428. #endif /* TERM_HELP */
  429.